package com.zjt.dao.user;

import com.zjt.entity.Record;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
 * 物码中心数据采集的DAO interface;
 * 
 * @author xueyanbeijing
 */
public interface IRecordDao extends JpaRepository<Record,Long>{
    List<Record> findByUserId(long userId);

    /**
     * 根据据Userid查询 记录，分页
     * @param userId
     * @param pageable
     * @return
     */
   // List<Record> findByUserId(long userId,Pageable pageable);
    Page<Record> findByUserId(long userId,Pageable pageable);

    Record findByCodeTypeAndCodeValue(String codeType,String codeValue);

    /**
     * 根据类型查询扫描记录
     * @param codeType
     * @param userId
     * @return
     */
    List<Record> findByCodeTypeAndUserId(String codeType,long userId);
    List<Record> findByCodeType(String codeType);

    @Query("select count(*) from Record u where u.userId = :userId")
    long countByQueryUserId(@Param("userId")long userId);

    @Query("select count(*) from Record u where u.codeValue = :codeValue")
    long countByQueryCodeValue(@Param("codeValue") String codeValue);
    /**
     * 根据用户Id,与产品ID取扫描对像
     * @param userId
     * @param productId
     * @return
     */
    Record findByUserIdAndProductId(long userId,long productId);

    /**
     * 根据用户ID和条码或者二维码ID定位一条记录
     *
     * @param userId
     * @param codeValue
     * @return
     */
    Record findByUserIdAndCodeValue(long userId, String codeValue);




}
